package cn.interestingshop.service.orderInfo;

import cn.interestingshop.dao.OrderInfoDao;
import cn.interestingshop.dao.OrderInfoDaoImpl;
import cn.interestingshop.entity.OrderInfo;
import cn.interestingshop.utils.DataSourceUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class OrderInfoServiceImpl implements OrderInfoService{
    @Override
    public int insert(OrderInfo orderInfo) {

        Connection conn=null;
        int rs=0;

        try {
            conn= DataSourceUtil.openConnection();
            OrderInfoDao orderInfoDao=new OrderInfoDaoImpl(conn);

            rs=orderInfoDao.insert(orderInfo);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return rs;
    }

    @Override
    public List<OrderInfo> selectOne(int id) {

        Connection conn=null;
        List<OrderInfo> list=new ArrayList<>();

        try {
            conn=DataSourceUtil.openConnection();
            OrderInfoDao orderInfoDao=new OrderInfoDaoImpl(conn);

            list= orderInfoDao.selectOne(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DataSourceUtil.closeConnection(conn);
        }


        return list;
    }
}
